package com.tongcao.cn.algorithm;

import com.google.common.util.concurrent.RateLimiter;

/**
 * @Author:tongcao
 * @Date:2019/3/22 15:17
 * Description:
 */
public class RateLimiterMain {
    /**
     * 限流算法(漏桶算法)
     */
    private static void ratelimit() {
        RateLimiter limiter = RateLimiter.create(10);
        while (1 == 1) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    if (limiter.tryAcquire()) {
                        limiter.acquire();
                        System.out.println("pass");
                    } else {
                        System.out.println("limit");
                    }
                }
            }).start();
        }
    }


    public static void main(String[] args) {
        ratelimit();
    }
}
